package com.nut.service.impl;

import com.nut.pojo.User;
import com.nut.service.UserService;
import com.nut.dao.UserDao;
import com.nut.dao.impl.UserDaoImpl;

public class UserServiceImpl implements UserService {

    private final UserDao userDao = new UserDaoImpl();

    @Override
    public void registUser(User user) {
        userDao.saveUser(user);

    }
    @Override
    public User login(User user) {
        return userDao.queryUserByUsernameAndPassword(user.getUsername(), user.getPassword());
    }

    @Override
    public boolean existsUsername(String username) {
        if (userDao.queryUserByUsername(username) == null) {
           // 等于null,说明没查到，没查到表示可用
           return false;
        }
        return true;

    }

    @Override
    public Integer getUserMaxId() {
        return userDao.getUserMaxId();
    }

    @Override
    public Integer getUserIdByUsername(String username) {
        return userDao.getUserIdByUsername(username);
    }
}
